package com.cn.lp.export.server.base.context;

import com.cn.lp.export.server.base.result.ResultCode;

/**
 * Created by xiaoqing on 2018/5/6.
 */
public class ResponseResultFactory {

    /**
     * 成功不返回数据
     */
    public final static CommandResult SUCC = new ResponseResult().setResultCode(CoreResponseCode.SUCCESS.getCode());

    /**
     * 创建成功响应结果
     * <p>
     * <p>
     * 创建成功响应结果<br>
     *
     * @param message 信息体
     * @return 返回响应结果
     */
    public static CommandResult success(Object message) {
        return new ResponseResult()
            .setResultCode(CoreResponseCode.SUCCESS.getCode())
            .setMessage(message);
    }

    /**
     * 创建成功响应结果
     * <p>
     * <p>
     * 创建成功响应结果<br>
     *
     * @return 返回响应结果
     */
    public static CommandResult success() {
        return SUCC;
    }

    /**
     * 创建失败响应结果
     * <p>
     * <p>
     * 创建失败响应结果<br>
     * <p>
     * 消息体
     *
     * @return 返回响应结果
     */
    public static CommandResult fail(ResultCode responseCode) {
        return new ResponseResult()
            .setResultCode(responseCode.getCode())
            .setErrorMsg(responseCode.getMessage());
    }

    /**
     * 创建失败响应结果
     * <p>
     * <p>
     * 创建失败响应结果<br>
     *
     * @param code 结果码
     * @return 返回响应结果
     */
    public static CommandResult fail(int code, Object errorMsg) {
        return new ResponseResult()
            .setResultCode(code)
            .setErrorMsg(errorMsg);
    }

}
